﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using WJ.Infrastructure.Cache;
using WJ.Infrastructure.Data;
using WJ.Infrastructure.DDD;
using WJ.Infrastructure.EntitiesExtension;

namespace WJ.Infrastructure.NH
{
    public class QueryBase<TEntity> : IQuery<TEntity> where TEntity : class, IEntity, new()
    {
        protected NHContext Dbcontext;

        public QueryBase()
        {
            Dbcontext = IoC.Resolve<IUnitOfWork>() as NHContext;

        }


        public TEntity GetOne(Expression<Func<TEntity, bool>> exp)
        {
            return Dbcontext.GetOne(exp);
        }

        public PageData<TEntity> GetList(Expression<Func<TEntity, bool>> exp, int pagesize, int pageindex, bool istotal)
        {
            return Dbcontext.GetList(exp, pagesize, pageindex, istotal);
        }

        public List<TEntity> GetList(Expression<Func<TEntity, bool>> exp)
        {
            return Dbcontext.GetList(exp);
        }

        public IQueryable<TEntity> GetListQuery(Expression<Func<TEntity, bool>> exp)
        {
            return Dbcontext.GetListQuery(exp);
        }

        public bool Exists(Expression<Func<TEntity, bool>> exp)
        {
            return Dbcontext.Exists(exp);
        }

        public List<TEntity> TopN(Expression<Func<TEntity, bool>> condition, int topN)
        {
            return Dbcontext.TopN(condition, topN);
        }


    }
}